package com.shauvik.client;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class CheckboxCountdown extends IOCountdown {
	
	public Widget buildSeparator(){
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.setSpacing(5);
		for(int i=0;i<2;i++){
			CheckBox sep = new CheckBox();
			sep.setEnabled(false);
			vPanel.add(sep);
		}
		return vPanel;
	}
	
	public Widget buildNumber(int id, String style){
		CheckBox[][] ptr = new CheckBox[4][7];
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.setStyleName(style);
		vPanel.setSpacing(0);
		for(int j=0;j<7;j++){ 
			HorizontalPanel hPanel = new HorizontalPanel();
		    hPanel.setSpacing(0);
		    for(int i=0;i<4;i++){
		    	ptr[i][j] = new CheckBox();
		    	hPanel.add(ptr[i][j]);
		    }
		    vPanel.add(hPanel);
		}
		pointers.add(ptr);
		return vPanel;
	}

	@Override
	public void animate(int[] old_digits, int[] digits) {
		for(int i=8;i>=0;i--){
			if(digits[i] == old_digits[i]){
				return;
			}
			CheckBox[][] ptr = (CheckBox[][]) pointers.get(i);
			int[][] dig = Constants.num[digits[i]];
			for(int a=0;a<dig.length;a++){
				for(int b=0; b<dig[a].length;b++){
					//GWT.log(a+","+b);
					if(dig[a][b]==1){
						ptr[b][a].setValue(true);
						ptr[b][a].addStyleName("selected");
					}else{
						ptr[b][a].setValue(false);
						ptr[b][a].removeStyleName("selected");
					}
				}
			}
		}
	}
	
	

}
